//
//  SettingsApi.m
//  Api
//
//  Created by CPX on 2018/6/19.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "SettingsApi.h"

/**
 设置相关接口
 @author yzl
 */
@implementation SettingsApi

+ (void)getLanguageList:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",QURANRootURL,LanguagesPath];
    [NetworkManager GETWithURL:url header:[self header] params:nil success:^(id response) {
        if (response[@"code"] && [response[@"code"] integerValue] == 0) {
            success(response[@"data"]);
        }
        else{
            failure(nil);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)downloadTranslation:(NSDictionary*)params progress:(DownloadProgress)progress success:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",QURANRootURL,TranslationPath];
    [NetworkManager GETWithURL:url header:[self header] params:params progress:progress success:^(id response) {
        if (response[@"code"] && [response[@"code"] integerValue] == 0) {
            success(response[@"data"]);
        }
        else{
            failure(nil);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)downloadTranslationV2:(NSDictionary*)params progress:(DownloadProgress)progress success:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",QURANRootURL,TranslationPath];
    [NetworkManager GETWithURL:url header:[self header] params:params progress:progress success:^(id response) {
        if (response[@"code"] && [response[@"code"] integerValue] == 0) {
            success(response[@"data"]);
        }
        else{
            failure(nil);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)getUpdateInfoWithSuccess:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",RootURL,VersionPath];
    [NetworkManager GETWithURL:url header:[self header] params:@{@"os_type":@"ios"} success:^(id response) {
        if([self dealWithResponse:response]){
            success(response[@"data"]);
        }
    } failure:^(NSError *error) {
        NSDictionary* data = [self dealError:error];
        if (data) {
            success(data);
        }
        else{
            failure(error);
        }
    }];
}

@end
